
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "settings.h"
#include "flash.h"

MI_S32 get_current_times(MI_CHAR *c_time)
{
    time_t timep;
    struct tm *p;
    time(&timep);
    p = gmtime(&timep);

    sprintf(c_time,"%04d%02d%02d %02d%02d%02d",p->tm_year + 1900,p->tm_mon + 1,p->tm_mday,
                                            p->tm_hour + 8,p->tm_min,p->tm_sec);

    return 0;
}

MI_S32 main(int argc,char *argv[])
{
    system_info s_info;
    FILE *file;
    size_t w_size;

#ifdef USER_PRODUCT_A
    MI_CHAR *board_name = "N32G430C8L7_STB_A";
#endif

#ifdef USER_PRODUCT_B
    MI_CHAR *board_name = "N32G430C8L7_STB_B";
#endif

    memset(&s_info,0,sizeof(s_info));
    get_current_times(s_info.app_version);
    get_current_times(s_info.settings_version);
    get_current_times(s_info.soft_version);
    get_current_times(s_info.boot_version);
    memcpy(s_info.board_name,board_name,strlen(board_name));

    printf(FONT_COLOR_BLUE"get current time %s\n"COLOR_NONE,s_info.app_version);

    printf(FONT_COLOR_BLUE"get board name %s\n"COLOR_NONE,s_info.board_name);

    file = fopen("./build/Settings.bin","wb");

    if (file == NULL)
    {
        printf(FONT_COLOR_YELLOW" open settings.bin error\n"COLOR_NONE);
        return -1;
    }
    w_size = fwrite((MI_U8 *)&s_info,1,sizeof(s_info),file);
    if (w_size == sizeof(system_info))
    {
        printf(FONT_COLOR_YELLOW" creat settings.bin Success!\n"COLOR_NONE);
    }
    fclose(file);
    return 0;
}